<template>
	<view class="Recharge_content">
		<view class="header">
			<view class="back">
				<image src="../../static/image/me_back.png" @tap="back"></image>
			</view>
			<image src="../../static/image/avator.png" class="avator" ></image>
			<text class="user_account" @tap="copy(account_info.accountName)">{{account_info.accountName}}<text class="fz">{{i18n.mecopy}}</text></text>
			
			<text class="user_phone">{{phone}}</text>
		</view>
		 <view class="kg">
			<image
			:src="eye?'../../static/image/en.png':'../../static/image/zh.png'" 
			@tap="tapnum"
			class="eyes"></image>
		 </view>
		<view class="user_content">
			<view class="top">
				<view class="top_item" @tap="transaction">
					<view class="item_left">
						<image src="../../static/image/transation.png" class="all_icon"></image>
						<text>{{i18n.syjy}}</text>
					</view>
					<image src="../../static/image/arrow.png" class="arrow"></image>
				</view>
				
				<view class="top_item" @tap="exportKey">
					<view class="item_left">
						<image src="../../static/image/key_icon.png" class="key"></image>
						<text>{{i18n.dcsy}}</text>
					</view>
					<image src="../../static/image/arrow.png" class="arrow"></image>
				</view>
				
				<view class="top_item" @tap="contact">
					<view class="item_left">
						<image src="../../static/image/contact.png" class="contact"></image>
						<text>{{i18n.lxwm}}</text>
					</view>
					<image src="../../static/image/arrow.png" class="arrow"></image>
				</view>
				
				<view class="top_item" @tap="share">
					<view class="item_left">
						<image src="../../static/image/share.png" class="contact"></image>
						<text>{{i18n.fxhy}}</text>
					</view>
					<image src="../../static/image/arrow.png" class="arrow"></image>
				</view>
				
				<view class="top_item" @tap="edition">
					<view class="item_left">
						<image src="../../static/image/update_edition.png" class="update"></image>
						<text>{{i18n.bbgx}}</text>
					</view>
					<image src="../../static/image/arrow.png" class="arrow"></image>
				</view>
			</view>
			
			<image :src="i18n.tc" class="logout" @tap="logout"></image>
		</view>
		
	</view>
</template>

<script>
	//import * as oex from 'oex-web3'; 
	import account from '../../common/account.js'
	import {myMixins} from '../../common/mixins.js'
	export default {
		computed: {
			i18n() {
				return this.$t('user')
			}
		},
		mixins: [myMixins], // 使用mixin
		data() {
			var Language = uni.getStorageSync('system_info');
			return {
				language:"",
				accountInfomation:"",  //账户全部信息
				accountName:"",  //账户名
				accountID:"",    //账户ID
				phone:"",
				avator:"",
				yqmname:"",
				eye:false,
				// tapnum:""
				}
		},
		onLoad() {
			var _this=this
			//console.log(_this.avator)
			  uni.getStorage({
					key:'language',
					success(e){
					_this.language=e.data
					if(e.data=='zh'){
						_this.eye=true
					}else{
						 _this.eye=false
					}
					}
			  })
			//获取手机号
			this.getUserInfo();
			
		},
		methods: {
			chageEye(){
				this.eye = !this.eye;
			},
			tapnum(){
				var _this = this;
				this.eye = !this.eye;
				let system_info = uni.getStorageSync('system_info');
				if(system_info == "zh_CN") _this._i18n.locale = 'en';
				else  _this._i18n.locale = 'zh_CN';
				uni.setStorageSync('system_info',_this._i18n.locale);
			},
			async  accountInfo(){
				 //加载账户
				const _this = this;
				await  account.getAccount().then(res =>{
					//console.log(res)
					_this.accountInfomation = res.data.result;
					_this.accountName = res.data.result.accountName;
					_this.accountID = res.data.result.accountID;
					_this.yqmname= res.data.result.invitationcode
					//console.log(res.data.result.invitationcode)
					uni.setStorage({
						key:"accountName",
						data:res.data.result.accountName
					})
					
				}).catch(error =>{
					console.log(error)
				})
				this.getUserInfo(_this.accountName)
			},
			getUserInfo(){
				//获取手机号
				const _this = this;
				const data = { account: this.account_info.accountName};
				account.getuserInfo(data).then(res =>{
					//console.log(res)
					if(res.code == 200){
							//_this.phone = _this.$CommonJS.initPhone(res.data.mobile)
							_this.phone = res.data.mobile;
							_this.yqmname=res.data.invitationcode
							_this.accountName=res.data.account
					}
				}).catch(error =>{
					console.log(error)
				})
			},
			back(){
				this.$CommonJS.navigateBack()
			},
			share(){
				console.log(this.accountName)
				this.$CommonJS.navigateTo('../share/share?yqmname='+this.yqmname+'&accountName='+this.accountName)
			},
			// chageAvator(){
			// 	const _this = this;
			// 	 // 预览图片
			// 		uni.previewImage({
			// 				urls: [this.avator],
			// 				longPressActions: {
			// 						itemList:this._i18n.locale == 'zh_CN' ? ['上传头像', '保存图片'] : ['Upload Avatar', 'Save Picture'],
			// 						success: function(data) {
			// 								//console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
			// 								if(data.tapIndex == 0){
			// 									//上传
			// 									uni.chooseImage({
			// 									    count: 1, //默认9
			// 									    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			// 									    sourceType: ['album'], //从相册选择
			// 									    success: function (res) {
			// 												plus.io.getImageInfo({
			// 														src: res.tempFilePaths[0],
			// 														success: function (image) {
			// 																uni.setStorage({
			// 																	key:'avator',
			// 																	data:image.path,
			// 																	success(res) {
			// 																		_this.avator = image.path;
			// 																		uni.showToast({
			// 																			title:_this._i18n.locale == 'zh_CN' ? '已上传':'Uploaded',
			// 																		})
			// 																	}
			// 																})
			// 																// uni.getStorage({
			// 																//     key: 'avator',
			// 																//     success: function (res) {
			// 																//         console.log(res.data);
			// 																//     }
			// 																// }); 
			// 														}
			// 												});
			// 									    }
			// 									});
			// 								}else if(data.tapIndex == 1){
			// 									uni.saveImageToPhotosAlbum({
			// 											filePath: _this.avator,
			// 											success: function () {
			// 													uni.showToast({
			// 														title:_this._i18n.locale == 'zh_CN' ? '已保存':'Saved',
			// 													})
			// 											}
			// 									});
			// 								}
			// 						},
			// 						fail: function(err) {
			// 								console.log(err.errMsg);
			// 						}
			// 				}
			// 		});
			// },
			logout(){
				//退出登录
				const _this = this;
				uni.showLoading();
				uni.removeStorage({
				    key: 'account_info',
				    success: function (res) {
				        uni.setStorage({
				        	key:'login_status',
									data:false,
									success() {
										uni.hideLoading();
										uni.showToast({
											title:_this._i18n.locale == 'zh_CN' ? '已退出':'Exited',
											success() {
												_this.$CommonJS.navigateTo('../index/home')
											}
										})
									}
				        })
				    }
				});
				 
			},
			exportKey(){
				this.$CommonJS.navigateTo('./export_key')
			},
			transaction(){
				this.$CommonJS.navigateTo('./transaction')
			},
			contact(){
				this.$CommonJS.navigateTo('./contact')
			},
			edition(){
				this.$CommonJS.navigateTo('./edition')
			},
			copy(value){
				//提示模板
				const _this = this;
				uni.setClipboardData({
					data:value,//要被复制的内容
					success:()=>{//复制成功的回调函数
						uni.showToast({//提示
							title:_this._i18n.locale == 'zh_CN' ? '已复制':'Copied',
						})
					}
				});
			},
		},
		
	}
</script>

<style lang="stylus">
	@import "../../static/stylus/me/me.stylus"
</style>
